package com.bdwm.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
 * 数据库连接相关配置
 * @author wangwenhui
 *
 */
public class DataBaseConn {
	public static Connection mysqlConn() throws ClassNotFoundException, SQLException {
		Connection conn = null;
		String db_ip = "localhost";
//		String db_ip = "39.106.200.38";
		String db_port = "3306";
		String db_name = "MDM";   
		String db_user = "root";
		String db_pwd = "letmein";
//		String db_pwd = "admin";
		Class.forName("com.mysql.jdbc.Driver");
//		String url="jdbc:mysql://39.106.200.38:3306/mdm?autoReconnect=true&user=root&password=letmein";
		conn = DriverManager.getConnection("jdbc:mysql://" + db_ip + ":" + db_port + "/" + db_name + "?useUnicode=true&characterEncoding=UTF-8", db_user, db_pwd);
//		conn = DriverManager.getConnection(url);
		return conn;
	}

	public static void closeDB(ResultSet rs, PreparedStatement ps, Connection conn) {
		try {
			if (rs != null) {
				rs.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			if (ps != null) {
				ps.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			if (conn != null) {
				conn.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}